package cn.guestbook.dao.impl;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.guestbook.dao.UserDAO;
import cn.guestbook.model.User;

public class UserDAOImpl extends HibernateDaoSupport implements UserDAO {
	public void add(User user) throws DataAccessException {
		getHibernateTemplate().save(user);
	}

	public void deleteById(Integer id) throws DataAccessException {
		String hql = "delete from User where userId = ?";
		getHibernateTemplate().bulkUpdate(hql, id);
		
	}

	public void update(User user) throws DataAccessException {
		getHibernateTemplate().update(user);
	}
	
	public User findById(Integer id) throws DataAccessException{
		return (User) getHibernateTemplate().get(User.class, id);
	}

	@SuppressWarnings("unchecked")
	public List<User> findAll() throws DataAccessException {
		return getHibernateTemplate().find("from User");
	}

	
}
